import {
    addActivity,
    addNotice,
    addReward,
    deleteActivity,
    deleteNotice,
    deleteReward,
    queryActivity,
    queryActivityCnt,
    queryNotice,
    queryNoticeCnt,
    queryReward,
    queryRewardCnt,
} from './apidata.js';

export const Tabs = Object.freeze({
    TabIndex: '首页',
    TabReward: '奖励',
    TabActivity: '活动',
    TabNotice: '公告',
});

export const TabIcons = new Map([
    [Tabs.TabIndex, "image/index.png"],
    [Tabs.TabReward, "image/reward.png"],
    [Tabs.TabActivity, "image/event.png"],
    [Tabs.TabNotice, "image/notice.png"],
]);

export const TableHeaders = new Map([
    [Tabs.TabIndex, []],
    [Tabs.TabReward, ['管理员', '玩家名称', '奖励内容', '发放时间', '操作']],
    [Tabs.TabActivity, ['管理员', '活动ID', '活动名称', '开始时间', '结束时间', '操作']],
    [Tabs.TabNotice, ['管理员', '发放时间', '消失时间', '公告内容', '操作']],
]);

export const Rules = Object.freeze({
    Truncate20: truncate20,
    Truncate200: truncate200,
});

export const TableColumnRule = new Map([
    [Tabs.TabIndex, []],
    [Tabs.TabReward, [null, Rules.Truncate200, Rules.Truncate20, Rules.Truncate20, null]],
    [Tabs.TabActivity, [null, Rules.Truncate20, Rules.Truncate20, Rules.Truncate20, Rules.Truncate20, null]],
    [Tabs.TabNotice, [null, Rules.Truncate20, Rules.Truncate20, Rules.Truncate200, null]],
]);

export const TableButtonName = Object.freeze({
    Save: '保存',
    Add: '新增',
    Delete: '删除',
});

export const TabTitles = new Map([
    [Tabs.TabIndex, '首页'],
    [Tabs.TabReward, '奖励信息'],
    [Tabs.TabActivity, '活动信息'],
    [Tabs.TabNotice, '公告信息'],
]);

export const HasAddIcon = new Map([
    [Tabs.TabIndex, false],
    [Tabs.TabReward, true],
    [Tabs.TabActivity, true],
    [Tabs.TabNotice, true],
]);

export const TableColumnTypes = new Map([
    [Tabs.TabIndex, []],
    [Tabs.TabReward, ['select', 'text', 'text', 'date', 'button']],
    [Tabs.TabActivity, ['select', 'text', 'text', 'date', 'date', 'button']],
    [Tabs.TabNotice, ['select', 'date', 'date', 'text', 'button']],
]);

export const TabColumnNames = new Map([
    [Tabs.TabIndex, []],
    [Tabs.TabReward, ['gm', 'player', 'reward', 'datetime']],
    [Tabs.TabActivity, ['gm', 'activity_id', 'activity_name', 'start_time', 'end_time']],
    [Tabs.TabNotice, ['gm', 'send_time', 'exit_time', 'content']],
]);

export const TabColumnKeys = new Map([
    [Tabs.TabIndex, ''],
    [Tabs.TabReward, 'id'],
    [Tabs.TabActivity, 'id'],
    [Tabs.TabNotice, 'id'],
]);

export const TabAddRequests = new Map([
    [Tabs.TabIndex, null],
    [Tabs.TabReward, addReward],
    [Tabs.TabActivity, addActivity],
    [Tabs.TabNotice, addNotice],
]);

export const TabDeleteRequests = new Map([
    [Tabs.TabIndex, null],
    [Tabs.TabReward, deleteReward],
    [Tabs.TabActivity, deleteActivity],
    [Tabs.TabNotice, deleteNotice],
]);

export const TabQueryCntRequests = new Map([
    [Tabs.TabIndex, null],
    [Tabs.TabReward, queryRewardCnt],
    [Tabs.TabActivity, queryActivityCnt],
    [Tabs.TabNotice, queryNoticeCnt],
]);

export const TabQueryRequests = new Map([
    [Tabs.TabIndex, null],
    [Tabs.TabReward, queryReward],
    [Tabs.TabActivity, queryActivity],
    [Tabs.TabNotice, queryNotice],
]);

export const TabPageCapacities = new Map([
    [Tabs.TabIndex, 5],
    [Tabs.TabReward, 10],
    [Tabs.TabActivity, 10],
    [Tabs.TabNotice, 10],
]);

function truncate20(s) {
    return truncate(s, 20);
}

function truncate200(s) {
    return truncate(s, 200);
}

function truncate(s, n) {
    if (s.length > n) {
        return s.slice(0, n);
    }
    return s;
}


